#!/bin/sh
echo "lmdprogress:2"
source "${LMD_BASE_INSTALL_SCRIPT_DIR}/global/sys_check.sh"

echo "lmdprogress:3"
source "${LMD_BASE_INSTALL_SCRIPT_DIR}/global/install_conda.sh"
source "${LMD_BASE_INSTALL_SCRIPT_DIR}/global/conda_run.sh"
source "${LMD_BASE_INSTALL_SCRIPT_DIR}/global/conda_and_pip_settings.sh"

echo "lmdprogress:10"
APP_INSTALL_NAME="n8n-workflows"
export CURRENT_APP_PATH="${LMD_APPS_DIR}/${APP_INSTALL_NAME}"
echo $CURRENT_APP_PATH
mkdir -p "$CURRENT_APP_PATH"

if [ -d "$CURRENT_APP_PATH" ]; then
  echo "App Dir: "$CURRENT_APP_PATH
else
  echo "Error, App Dir dose not exist, please retry. "$CURRENT_APP_PATH
  exit 1
fi

source "$LMD_BASE_INSTALL_SCRIPT_DIR/apps/${APP_INSTALL_NAME}/env"
export GIT_HOST=${GITHUB_PROXY}"https://github.com"

echo "lmdprogress:16"
export GIT_LFS_SKIP_SMUDGE=1

export GIT_HOST=${GITHUB_PROXY}"https://github.com"
export GIT_REPO_URL="${GIT_HOST}/Zie619/n8n-workflows"
export GIT_REPO_BRANCH="main"
export LOCAL_REPO_PATH="$CURRENT_APP_PATH"
sh "${LMD_BASE_INSTALL_SCRIPT_DIR}/global/git_clone_and_fetch.sh"

echo "lmdprogress:38"

cd "$CURRENT_APP_PATH"
CONDA_PREFIX="./venv"

if [ -d "$CONDA_PREFIX" ]; then
    echo "found ./venv. remove it. "
    rm -rf "$CONDA_PREFIX"
fi

export PYTHON_VER_ENV=3.12
conda_create_env $CONDA_PREFIX python=$PYTHON_VER_ENV pip=25.2 -y


echo "lmdprogress:70"

conda_run_pip_install -r requirements.txt


echo "lmdprogress:100"
